package cn.aion.dao;

import cn.aion.model.ProjectVideo;
import cn.aion.model.ScanYouku;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 对应ad_project_video表
 * Created by Aion on 2016/11/2.
 */
public interface ProjectVideoDAO {
    @Select("select * from ad_project_video where id=#{id}")
    ProjectVideo selectOne(@Param("id") Integer id);

    @Select("select * from ad_project_video where iqiyi_url like concat(#{url},'%' )")
    ProjectVideo selectOneByIqiyi(@Param("url") String url);

    @Select("select * from ad_project_video where qq_url=#{url}")
    ProjectVideo selectOneByQQ(@Param("url") String url);

    @Select("select * from ad_project_video where sohu_url like concat('%', #{videoId},'%' )")
    ProjectVideo selectOneBySohu(@Param("videoId") String videoId);

    @Select("select * from ad_project_video where youku_url like concat('%', #{videoId},'%' )")
    ProjectVideo selectOneByYouku(@Param("videoId") String videoId);

    @Select("select * from ad_project_video where bilibili_url like concat('%', #{videoId},'%' )")
    ProjectVideo selectOneByBilibili(@Param("videoId") String videoId);

    @Select("select * from ad_project_video where toutiao_url=#{url}")
    ProjectVideo selectOneByToutiao(@Param("url") String url);

    @Select("select * from ad_project_video where miaopai_url=#{url}")
    ProjectVideo selectOneByMiaopai(@Param("url") String url);

    @Select("select * from ad_project_video where meipai_url=#{url} limit 1")
    ProjectVideo selectOneByMeipai(@Param("url") String url);

    @Select("select * from ad_project_video where tudou_url like concat('%', #{videoId},'%' )")
    ProjectVideo selectOneByTudou(@Param("videoId") String videoId);

    @Select("select * from ad_project_video where acfun_url like concat('%', #{videoId},'%' )")
    ProjectVideo selectOneByAcfun(@Param("videoId") String videoId);

    @Select("select * from ad_project_video where status between 2 and 3")
    List<ProjectVideo> getVideoAll();

    @Select("select count(*) from ad_project_video where status>2")
    int getTotal();

    @Select("select * from ad_project_video where status>2 limit #{start},#{total}")
    List<ProjectVideo> getVideoPage(@Param("start") Integer start, @Param("total") Integer total);

    @Update("update ad_project_video set youku_vv=#{count} where id=#{id}")
    int updateYoukuVideoCount(@Param("id") Long id, @Param("count") int count);

    @Update("update ad_project_video set iqiyi_vv=#{count} where id=#{id}")
    int updateIqiyiVideoCount(@Param("id") Long id, @Param("count") int count);

    @Update("update ad_project_video set qq_vv=#{count} where id=#{id}")
    int updateQQVideoCount(@Param("id") Long id, @Param("count") int count);

    @Update("update ad_project_video set sohu_vv=#{count} where id=#{id}")
    int updateSohuVideoCount(@Param("id") Long id, @Param("count") int count);

    @Update("update ad_project_video set bilibili_vv=#{count} where id=#{id}")
    int updateBilibiliVideoCount(@Param("id") Long id, @Param("count") int count);

    @Update("update ad_project_video set toutiao_vv=#{count} where id=#{id}")
    int updateToutiaoVideoCount(@Param("id") Long id, @Param("count") int count);

    @Update("update ad_project_video set tudou_vv=#{count} where id=#{id}")
    int updateTudouVideoCount(@Param("id") Long id, @Param("count") int count);

    @Update("update ad_project_video set miaopai_vv=#{count} where id=#{id}")
    int updateMiaopaiVideoCount(@Param("id") Long id, @Param("count") int count);

    @Update("update ad_project_video set meipai_vv=#{count} where id=#{id}")
    int updateMeipaiVideoCount(@Param("id") Long id, @Param("count") int count);

    @Update("update ad_project_video set acfun_vv=#{count} where id=#{id}")
    int updateAcfunVideoCount(@Param("id") Long id, @Param("count") int count);

    @Update("update ad_project_video " +
            "set total_vv=youku_vv+iqiyi_vv+qq_vv+sohu_vv+bilibili_vv+toutiao_vv+tudou_vv+miaopai_vv+meipai_vv " +
            "where id=#{id}")
    int updateTotal(@Param("id") Long id);

    @Update("update ad_apply set completed=#{count} where anchor_id=#{anchor_id} and project_id=#{project_id}")
    int updateApplyTotal(@Param("project_id") int projectId, @Param("anchor_id") int anchorId, @Param("count") int count);
}
